package fr.afcepf.ticketing.service;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import fr.afcepf.ticketing.dao.OrderDao;
import fr.afcepf.ticketing.domain.Address;
import fr.afcepf.ticketing.domain.CreditCard;
import fr.afcepf.ticketing.domain.Customer;
import fr.afcepf.ticketing.domain.Order;
import fr.afcepf.ticketing.domain.OrderLine;

@Stateless
public class OrderServiceBean implements OrderService {

	@EJB
	private OrderDao orderDao;

	@Override
	public Order getOrderByPk(Integer numero) {
		Order o =  orderDao.getEntityByPk(numero);
		o.getOrderLines().size();
		return orderDao.getEntityByPk(numero);
	}

	@Override
	public Collection<Order> getAllOrders() {
		Collection<Order> orders = orderDao.getAllOrders();
		for(Order o:orders)
			o.getOrderLines().size();
		return orderDao.getAllOrders();
	}

	@Override
	public void updateOrder(Order order) {
		orderDao.updateEntity(order);

	}

	@Override
	public void deleteOrder(int numero) {
		orderDao.deleteEntityFromPk(numero);

	}

	@Override
	public Collection<Order> getOrdersOfClient(Long numCli) {
		Collection<Order> orders = orderDao.getOrdersOfClient(numCli);
		for(Order o:orders)
			o.getOrderLines().size();
		return orders;
	}
	
	@Override
	public Collection<Order> getOrdersOfClient(Long numCli, Date date) {
		Collection<Order> orders = orderDao.getOrdersOfClient(numCli, date);
		for(Order o:orders)
			o.getOrderLines().size();
		return orders;
	}

	@Override
	public Collection<OrderLine> editOrderLineByOrder(Integer num) {
		Collection<OrderLine> orderLines = orderDao.editOrderLineByOrder(num);
		for (OrderLine orderLine : orderLines) {
			orderLine.getId();
		}
		return orderLines;
	}

	@Override
	public Order createNewOrder(Customer c, Address ad, CreditCard cb, List<CartTicket> ct) {
		return orderDao.createOrder(c, ad, cb, ct);
	}
	
	@Override
	public List<OrderLine> listOrderLines(List<CartTicket> cartTickets) {
		return orderDao.listOrderLines(cartTickets);
	}

	

	

}
